package com.example.company

import android.os.Build
import android.os.Bundle
import androidx.activity.viewModels
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.example.common.view.view.BaseMvvmActivity
import com.example.company.databinding.ActivityMerChantDetailBinding
import com.example.company.vm.CompanyViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/company/MerChantDetailActivity")
class MerChantDetailActivity : BaseMvvmActivity<ActivityMerChantDetailBinding>() {
    @Autowired
    @JvmField
    var merChantId:Int = 0
    private val merChantDetailViewModel:CompanyViewModel by viewModels()
    @RequiresApi(Build.VERSION_CODES.M)
    override fun initView() {
        ARouter.getInstance().inject(this)
        merChantDetailViewModel.getMerChantDetail(merChantId)
        //返回
        mDataBinding.enterpriseBack.setOnClickListener {
            finish()
        }
        merChantDetailViewModel.mMerChantDetailSuccess.observe(this){
            mDataBinding.applicationNumber.text = it.applicationNumber
            mDataBinding.enterpriseName.text = it.enterpriseName
            mDataBinding.peopleName.text = it.contactName
            mDataBinding.merchantTime.text = it.entryTime
            mDataBinding.applicationArea.text = it.applicationArea.toString()+"m²"
            mDataBinding.applicationCount.text = it.entryPersonnel.toString()+"m²"
            mDataBinding.applicationTime.text = it.entryTime
            mDataBinding.status.text = it.status
            if(it.status == "新建"){
                mDataBinding.square1.setBackgroundColor(getColor(com.example.resource.R.color.color_hui))
                mDataBinding.circle1.setBackgroundColor(getColor(com.example.resource.R.color.color_hui))
                mDataBinding.square2.setBackgroundColor(getColor(com.example.resource.R.color.color_hui))
                mDataBinding.circle23.setBackgroundColor(getColor(com.example.resource.R.color.color_hui))
            }else if(it.status == "待审核"){
                mDataBinding.square2.setBackgroundColor(getColor(com.example.resource.R.color.color_hui))
                mDataBinding.circle23.setBackgroundColor(getColor(com.example.resource.R.color.color_hui))
                mDataBinding.text2.setBackgroundColor(getColor(com.example.resource.R.color.color_hui))
                mDataBinding.text1.text = "待审核"
                mDataBinding.entryTime.text = it.entryTime
                mDataBinding.enterName.text = "发起人(${it.contactName})"
            }else if(it.status == "已审核"){
                mDataBinding.text1.text = "待审核"
                mDataBinding.entryTime.text = it.entryTime
                mDataBinding.enterName.text = "发起人(${it.contactName})"
                mDataBinding.text2.text = "审核通过"
            }else {
                mDataBinding.text1.text = "待审核"
                mDataBinding.entryTime.text = it.entryTime
                mDataBinding.enterName.text = "发起人(${it.contactName})"
                mDataBinding.text2.text = "已驳回"
            }
            ToastUtils.showLong(it.toString())
        }
        merChantDetailViewModel.mError.observe(this){
            ToastUtils.showLong("显示失败")
        }
    }

    override fun getLayoutId(): Int = R.layout.activity_mer_chant_detail
}